package com.jm.offer.easy;

/**
 * @Description https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/
 * @date 2022/4/11 12:04
 */
public class _18删除链表的节点 {

    public static void main(String[] args) {

    }

    public static ListNode deleteNode(ListNode head, int val) {
        if (head.val == val){
            return head.next;
        }
        ListNode pre = head;
        ListNode curr = head.next;
        while (curr.next != null && curr.val != val){
            pre = curr;
            curr = curr.next;
        }
        if (curr != null){
            pre.next = curr.next;
        }
        return head;

    }

    public static class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
  }
}
